package com.yoooya.base.third.utils.json.cp;

import com.google.gson.*;
import com.yoooya.base.third.model.vo.cp.WxCpTag;
import com.yoooya.base.third.utils.json.GsonHelper;

import java.lang.reflect.Type;

/**
 * 
 * @创建人 Sun Yijing
 * @创建时间 2018-07-08
 */
public class WxCpTagGsonAdapter implements JsonSerializer<WxCpTag>,
        JsonDeserializer<WxCpTag> {

	public JsonElement serialize(WxCpTag tag, Type typeOfSrc,
                                 JsonSerializationContext context) {
		JsonObject o = new JsonObject();
		o.addProperty("tagid", tag.getId());
		o.addProperty("tagname", tag.getName());
		return o;
	}

	public WxCpTag deserialize(JsonElement json, Type typeOfT,
                               JsonDeserializationContext context) throws JsonParseException {
		JsonObject jsonObject = json.getAsJsonObject();
		return new WxCpTag(GsonHelper.getString(jsonObject, "tagid"),
				GsonHelper.getString(jsonObject, "tagname"));
	}

}
